package com.naodong.shenluntiku.util;

import android.app.Activity;
import android.content.Context;
import android.view.View;

import com.luck.picture.lib.tools.PictureFileUtils;
import com.naodong.shenluntiku.mvp.view.activity.OnceTipActivityAutoBundle;

import io.reactivex.Observable;
import io.reactivex.ObservableOnSubscribe;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by hujie on 17/5/27.
 */

public class AppUtil {


    /**
     * 清除图片缓存
     * 包含拍照
     *  luban 压缩
     *  裁剪
     * @param context
     */
    public static void clearCacheImage(Context context) {

        Observable.create((ObservableOnSubscribe<Boolean>) e -> PictureFileUtils.deleteCacheDirFile(context)).subscribeOn(Schedulers.io()).subscribe();

    }


    public static void startOnceTipActivity(Activity activity, String type, View tartgetView) {


        if (tartgetView != null) {
            int[] highLightPosition = new int[2];
            tartgetView.getLocationOnScreen(highLightPosition);

            highLightPosition[0] = highLightPosition[0]+tartgetView.getWidth()/2;
            highLightPosition[1] = highLightPosition[1]+tartgetView.getHeight()/2;

            activity.startActivity(OnceTipActivityAutoBundle.builder(type).hightLightPositionX(highLightPosition[0]).hightLightPositionY(highLightPosition[1]).build(activity));
        } else {
            activity.startActivity(OnceTipActivityAutoBundle.builder(type).build(activity));
        }


        activity.overridePendingTransition(0, 0);
    }
}
